package com.qf.flash.mvp.presenter;


import com.qf.dblib.dao.impl.UserMgr;
import com.qf.flash.http.HttpManager;
import com.qf.flash.model.GroupDetailBean;
import com.qf.flash.mvp.contract.GroupSetContract;
import com.qf.flash.utils.AppToast;
import com.qf.flash.utils.LogUtil;
import com.qf.flashlib.base.BasePresenter;
import com.qf.flashlib.base.BaseResponse;
import com.qf.flashlib.base.BaseSubscriber;
import com.qf.flashlib.util.RxUtils;

public class GroupDetailPresenter extends BasePresenter<GroupSetContract.View> implements GroupSetContract.Presenter {
    @Override
    public void getGroupDetails(String groupId) {
        String id = UserMgr.getInstance().getLoginUser().getUid();
        addSubscription(HttpManager.getInstance().getGsonHttpApi()
                .GET_GAME_GROUP_BY_ID(id,groupId)
                .compose(RxUtils.handleBaseResult())
                .compose(RxUtils.io_main())
                .subscribeWith(new BaseSubscriber<BaseResponse<GroupDetailBean>>(mRootView) {
                    @Override
                    public void onSuccess(BaseResponse<GroupDetailBean> response) {
                        LogUtil.d("---response----"+response.getData());
                        mRootView.setUi(response.getData());
                    }
                })
        );
    }

    @Override
    public void outGroup(String groupId) {
        String id = UserMgr.getInstance().getLoginUser().getUid();
        addSubscription(HttpManager.getInstance().getGsonHttpApi()
                .OUT_GAME_GROUP(id,groupId)
                .compose(RxUtils.handleBaseResult())
                .compose(RxUtils.io_main())
                .subscribeWith(new BaseSubscriber<BaseResponse<Object>>(mRootView) {
                    @Override
                    public void onSuccess(BaseResponse<Object> response) {
                        LogUtil.d("---response----"+response.getData());
                        AppToast.showToast(" 操作成功！");
                        if (mRootView != null)
                            mRootView.groupOptionSuccess();
                    }
                })
        );
    }
}
